//
//  WKNewFeatureViewController.m
//  Walk
//
//  Created by cesh on 16/9/30.
//  Copyright © 2016年 cesh. All rights reserved.
//
#import "WKLoginViewController.h"
#import "WKNewFeatureViewController.h"

@interface WKNewFeatureViewController () <UICollectionViewDelegate, UICollectionViewDataSource>

@end

@implementation WKNewFeatureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    // 行间距
    flowLayout.minimumLineSpacing = 0;
    // 每个item 之间的间距
    flowLayout.minimumInteritemSpacing = 0;
    
    // 设置每个cell 的尺寸
    flowLayout.itemSize = CGSizeMake(screenW, screenH);
    
    // 设置滚动方向 水平滚动
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    UICollectionView *collectionV = [[UICollectionView alloc]initWithFrame:[UIScreen mainScreen].bounds collectionViewLayout:flowLayout];
    collectionV.dataSource = self;
    collectionV.delegate = self;
    collectionV.backgroundColor = [UIColor whiteColor];
    [collectionV registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    collectionV.showsHorizontalScrollIndicator = NO;
    collectionV.pagingEnabled = YES;
    [self.view addSubview:collectionV];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    UICollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    if (cell == nil) {
        cell = [[UICollectionViewCell alloc]init];
    }
    
    UIImageView *imgV = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    imgV.image = [UIImage imageNamed:[NSString stringWithFormat:@"newfeature_%li", (long)indexPath.row]];
    
    cell.backgroundView = imgV;
    
    if (indexPath.row == 3) {
        //添加进入app的按钮
        UIButton *enter = [[UIButton alloc]init];
        enter.size = CGSizeMake(200, 30);
        enter.center = CGPointMake(screenW * 0.5, screenH - 150);
        
        [enter setTitle:@"开启蛙客" forState:UIControlStateNormal];
        [enter setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [enter.titleLabel setFont:[UIFont systemFontOfSize:12.0]];
        enter.backgroundColor = [UIColor colorWithRed:0x4a / 255.0 green:0x4a / 255.0 blue:0x4a / 255.0 alpha:1.0];
        
        [cell.contentView addSubview:enter];
        
        [enter addTarget:self action:@selector(goToLoginVC) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return cell;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 4;
}

- (void)goToLoginVC {
    WKLoginViewController *loginVC = [[WKLoginViewController alloc]init];
    CATransition *anim = [CATransition animation];
    anim.type = @"rippleEffect";
    anim.duration = 1.0;
    [[UIApplication sharedApplication].keyWindow.layer addAnimation:anim forKey:nil];
    [self presentViewController:loginVC animated:NO completion:nil];
}

@end
